IF NOT EXISTS
(
	SELECT *
	FROM dbo.[sysobjects]
	WHERE [id]=OBJECT_ID(N'dbo.[ExampleTable.TargetId.TargetTable.Id.ForeignKey]') AND OBJECTPROPERTY(id, N'IsForeignKey')=1
)
	BEGIN
	ALTER TABLE dbo.[ExampleTable] ADD CONSTRAINT [ExampleTable.TargetId.TargetTable.Id.ForeignKey] FOREIGN KEY ([TargetId]) REFERENCES dbo.[TargetTable] ([Id])
	END
GO